package com.roncoo.course.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.course.entity.EduCourse;
import com.roncoo.course.entity.EduSubject;
import com.roncoo.course.entity.HomePrecinct;
import com.roncoo.course.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wdf
 * @since 2021-03-26
 */
@Controller
@Api(tags = "(eduCourse)")
@RequestMapping("/eduCourse")
public class EduCourseController {
    @Resource
    private EduCourseService courseService;

    @ApiOperation(value = "根据时间查询最新")
    @PostMapping("findByTime")
    @ResponseBody
    public List<EduCourse> findAllByZone(){
        return courseService.findByTime();
    }

    @ApiOperation(value = "根据标题查询课程")
    @PostMapping("findAllById")
    @ResponseBody
    public IPage<EduCourse> findAllById(Page page, EduCourse eduCourse, EduSubject eduSubject){
        System.out.println("=========");
        System.out.println(eduCourse);
        System.out.println(eduSubject);
        System.out.println("=========");
        return courseService.findAllById(page, eduCourse,eduSubject);
    }
    @ApiOperation(value = "根据讲师查询课程")
    @PostMapping("findAllByTeacher")
    @ResponseBody
    public List<EduCourse> findAllByTeacher(EduCourse eduCourse){
        System.out.println(eduCourse);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("lecturer_id",eduCourse.getLecturerId());
        if(eduCourse.getStatus() != null && eduCourse.getStatus() != -1)
        queryWrapper.eq("status",eduCourse.getStatus());
        return courseService.list(queryWrapper);
    }

    @ApiOperation(value = "更改课程状态或增加一个课程")
    @PostMapping("updateoradd")
    @ResponseBody
    public Boolean updateoradd(EduCourse eduCourse){
        System.out.println(eduCourse);
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("lecturer_id",eduCourse.getLecturerId());
//        if(eduCourse.getStatus() != null && eduCourse.getStatus() != -1)
//            queryWrapper.eq("status",eduCourse.getStatus());
        return courseService.saveOrUpdate(eduCourse);
    }


    /**
     * 根据id查询课程
     */
    @GetMapping("findByCid")
    @ResponseBody
    public EduCourse findByCid(Integer cid){
        return courseService.getById(cid);
    }

    @PostMapping("getPath")
    @ResponseBody
    public String getPath(MultipartFile file){
        return courseService.getPath(file);
    }
}

